package com.newsproject.service.impl;

import com.newsproject.mapper.ManagerMapper;
import com.newsproject.pojo.Post;
import com.newsproject.service.ManagerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ManagerServiceImpl implements ManagerService {
    @Autowired
    private ManagerMapper managerMapper;

    @Override
    public ResponseEntity<?> getPostByAuditStatus(Integer auditStatus, Integer pageNum, Integer pageSize) {
        if(pageNum == null || pageSize == null || pageNum < 1 || pageSize < 1){
            return ResponseEntity.badRequest().body("参数错误");
        }
        //计算起始索引
        Integer startIndex = (pageNum - 1) * pageSize;
        //调用mapper方法查询文章列表
        List<Post> posts = managerMapper.findPostByAuditStatus(auditStatus, startIndex, pageSize);
        if(posts == null || posts.size() < 1){
            return ResponseEntity.ok("没有更多文章");
        }
        //判断有没有下一页
        return ResponseEntity.ok(posts);


    }
}
